package com.liu.netty.service;

import com.liu.netty.dao.DriverDao;
import com.liu.netty.dao.RunInfoDao;
import com.liu.netty.entity.Driver;
import com.liu.netty.entity.RunInfo;
import com.liu.netty.pojo.Message;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import util.IdWorker;

import javax.transaction.Transactional;


@Service
@Transactional
public class RunInfoService {

    @Autowired
    private RunInfoDao runInfoDao;

    @Autowired
    private IdWorker idWorker;

    @Autowired
    private DriverDao driverDao;

     public void addRunInfo(RunInfo runInfo ,String objectAddress){
         runInfo.setId(idWorker.nextId()+"");

         Driver driver = driverDao.findByObjectAddress(objectAddress);
         runInfo.setDriver(driver);
         runInfoDao.save(runInfo);
     }

     public void addRunInfoFromClient(Message message ){
         RunInfo  runInfo = new RunInfo();
         BeanUtils.copyProperties(message,runInfo);
         addRunInfo(runInfo,message.getObjectAddress());



     }

}
